﻿using JVMTI_CONN_CONNECT;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace JVMTI_CORE_SHELL.Converters
{
    class DepthToMarginConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new Thickness((int)value * 10, 0, 0, 0);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    class ContentionStatsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var data = (IEnumerable<ILifeEvent>)value;
            return data.Count<ILifeEvent>(o => o.EmpahsizingEvent());
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    class ContentionStatsPctgConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var data = (IList<ILifeEvent>)value;
            if (data.Count == 0) return 0;
            double cnt = 0;
            for (int i = 0; i < data.Count() - 1; i++)
            {
                if (data[i + 1].EmpahsizingEvent() == false && data[i].EmpahsizingEvent())
                    cnt += data[i + 1].Timestamp - data[i].Timestamp;
            }
            return (data.Last().Timestamp - data[0].Timestamp) == 0 ? 1 : 100 * cnt / (data.Last().Timestamp - data[0].Timestamp);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    class ValueToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value == null ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
